package com.wenx.completablefuture;

/**
 * 对商店返回字符串的解析操作封装到此类
 * 通过传递shop对象返回的字符串给静态工厂方法parse，你可以得到Quote类的一个实例，
 * 它包含了shop的名称、折扣之前的价格，以及折扣代码
 */
public class Quote {

    private final String shopName;
    private final double price;
    private final Discount.Code disCountCode;

    public Quote(String shopName, double price, Discount.Code disCountCode) {
        this.shopName = shopName;
        this.price = price;
        this.disCountCode = disCountCode;
    }

    //解析
    public static Quote parse(String s) {
        String[] split = s.split(":");
        String shopName = split[0];
        double price = Double.parseDouble(split[1]);
        Discount.Code discountCode = Discount.Code.valueOf(split[2]);
        return new Quote(shopName, price, discountCode);
    }

    public String getShopName() {
        return shopName;
    }

    public double getPrice() {
        return price;
    }

    public Discount.Code getDisCountCode() {
        return disCountCode;
    }
}
